package reflect;

import java.lang.reflect.InvocationTargetException;

/**
 * @Author: Miyako
 * @Date: 2024-07-23-9:44
 * @Description:
 */
public class Constructor {

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        java.lang.Class aClass = Integer.class;
        java.lang.Class aClass1 = Double.class;
//       java.lang.reflect.Constructor constructor = aClass.getConstructor(int.class);//限定构造方法的类型
//        String o1 =(String) constructor.newInstance((byte)1);//
//        Double o2 =(double)constructor.newInstance(1);
//        Integer o4 = new Integer(1);
//        System.out.println(o1);

//        System.out.println(o1==o2);//false，使用Integer的构造方法创建的实例，不是同一个对象
//        System.out.println(o1.equals(o2));//true,重写了equals方法，所以两个实例的值相等
        java.lang.reflect.Constructor <Double> con = aClass1.getConstructor(String.class);
        Double o3 =con.newInstance("1.1");
        System.out.println(o3);
//        System.out.println(o3==o1);
//        System.out.println(o3.equals(o1));


    }
}
